package com.chb.entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author CHB
 * @createTime 2022-6-20 16:54
 */
public class SimpleUserDetails implements UserDetails {
    private SecurityUserInfo securityUserInfo;

    public SecurityUserInfo getUserInfo() {
        return securityUserInfo;
    }

    public void setUserInfo(SecurityUserInfo securityUserInfo) {
        this.securityUserInfo = securityUserInfo;
    }

    public SimpleUserDetails(SecurityUserInfo securityUserInfo){
        this.securityUserInfo = securityUserInfo;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return securityUserInfo.getAuthorities();
    }

    @Override
    public String getPassword() {
        return securityUserInfo.getPwd();
    }

    @Override
    public String getUsername() {
        return securityUserInfo.getName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
